package com.itcast.homework04.work10;

import java.math.BigDecimal;
import java.util.Scanner;

/*
请键盘录入5个("字符串小数"), 将这些小数, 累加起来, 要求必须保证精准度,请求求出这五个数中平均值,
要求四舍五入保留小数点2位
*/
public class Test {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请录入5个小数,以,号隔开：");
        String src = sc.next();
        String[] split = src.split(",");
        double sum=0;
        for (int i = 0; i < split.length; i++) {
            double v = Double.parseDouble(split[i]);
            sum+=v;
        }
        System.out.println("累加和为："+sum);
        BigDecimal bigDecimal = new BigDecimal(sum);
        BigDecimal divide = bigDecimal.divide(BigDecimal.valueOf(5), 2, BigDecimal.ROUND_HALF_UP);
        System.out.println("平均值四舍五入保留小数点2位："+divide);
    }
}
